package ds.factcom.domain.invoice;



import java.util.Date;
import java.util.Iterator;
import java.util.List;

import ds.factcom.domain.Domain;
import ds.factcom.domain.client.Client;
import ds.factcom.domain.item.Item;
import ds.factcom.domain.payment.Payment;

/**
 * 
 * @author Javier De Luca, Maximiliano Herrera, Matias Samblancat
 * Representa la factura
 */
public abstract class Invoice extends Domain{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5791457306424260243L;

	private static Integer lastId = 0;
	
	private Client client;
	private Date date;
	private List<Item> listItem;
	private final Float mountNet;
	private Float mountAbsoluty;
	
	//############ esto es para la bidireccionalidad ####################
	private Payment payment;

	public Invoice(Client client , List<Item> listItem) {
		lastId = this.generateId();
		this.setId(lastId);
		this.client = client;
		this.date = new Date();
		this.listItem = listItem;
		this.mountNet = generateMountNet();
		this.mountAbsoluty = generateMountAbsoluty();
	}

	private Float generateMountNet() {
		Float mountNet = new Float(0F);
		for (Iterator<Item> iterator = listItem.iterator(); iterator.hasNext();) {
			Item i = (Item) iterator.next();
			mountNet+= i.getTotalPrice();
		}
		return mountNet;
	}

	protected abstract Float generateMountAbsoluty();
	

	public Client getClient() {
		return client;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Override
	protected Integer getLastId() {
		return lastId;
	}
	
	//TODO probar bien esto del equal del invoice a ver si funciono bien
	//TODO Revisar este metodo, estaba con la version anterior de producto y no fue reemplazado                      
	@Override
	public boolean equals(Object arg0) {
//		Invoice invoice = (Invoice)arg0;
//		return this.client.equals(invoice.getClient()) && 
//			this.listProduct.equals(invoice.getListProduct());
		return false; 
	}

	//############ esto es para la bidireccionalidad ####################
	public Payment getPayment() {
		return payment;
	}

	public void setPayment(Payment payment) {
		this.payment = payment;
	}
	//################################

	public Float getMountNet() {
		return mountNet;
	}

	public Float getMountAbsoluty() {
		return mountAbsoluty;
	}

	public void setMountAbsoluty(Float mountAbsoluty) {
		this.mountAbsoluty = mountAbsoluty;
	}
	
	public List<Item> getListItem(){
		return this.listItem;
	}
	
	public Item getFirstItem(){
		return this.listItem.get(0);
	}

}
